﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.Model;

public partial class Empolyee_ChangeEmpolyeeWage :BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["ID"] != null)
            {
                BindEmpolyeeData();
            }
        }
    }

    private void BindEmpolyeeData()
    {
        int empolyeeID = Convert.ToInt32(Request.QueryString["ID"]);

        var empolyee = new EmpolyeeDAL().GetEmpolyeeInfoByEmpolyeeID(empolyeeID);

        if (empolyee != null)
        {
            EmpolyeeName.Text = empolyee.Name;
            LoginName.Text = empolyee.LoginName;
            labBasicWage.Text = empolyee.BasicWage.ToString();
            labLivingSubsidy.Text = empolyee.LivingSubsidy.ToString();
            labConfidential.Text = empolyee.Confidential.ToString();
            labAll.Text = empolyee.Other.ToString();
            labOther.Text =
                (empolyee.Other - empolyee.Confidential - empolyee.LivingSubsidy - empolyee.BasicWage).ToString();

            GridView1.DataSource = new EmpolyeeDAL().GetChangeEmpolyeeWageLogByEmplyeeId(empolyeeID);
            GridView1.DataBind();
        }
    }
   
    protected void Button1_Click(object sender, EventArgs e)
    {
        int empolyeeID = Convert.ToInt32(Request.QueryString["ID"]);


         int basicWage;

            try
            {
                basicWage = Convert.ToInt32(labBasicWage.Text);
                if(basicWage <0)
                {
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('基本工资不能小于0');</script>");
                    return;
                }
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('基本工资格式错误');</script>");
               return;
            }


         int LivingSubsidy;

            try
            {
                LivingSubsidy = Convert.ToInt32(labLivingSubsidy.Text);
                if (LivingSubsidy < 0)
                {
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('生活补贴不能小于0');</script>");
                    return;
                }
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('生活补贴格式错误');</script>");
               return;
            }


         int Confidential;

            try
            {
                Confidential = Convert.ToInt32(labConfidential.Text);
                if (Confidential < 0)
                {
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('保密费不能小于0');</script>");
                    return;
                }
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('保密费格式错误');</script>");
               return;
            }


         int Other;

            try
            {
                Other = Convert.ToInt32(labAll.Text);
                if (Other < 1700)
                {
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('底薪不能小于1700');</script>");
                    return;
                }
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('底薪格式错误');</script>");
               return;
            }

            new EmpolyeeDAL().ChangeEmpolyeeWage(empolyeeID, basicWage, LivingSubsidy, Confidential, Other, labRemark.Text.Trim(), Page.User.Identity.Name);
            AlterAndRedirect("保存成功", "EmpolyeeList.aspx");
    }
}